package org.thread.test03;

import java.util.concurrent.FutureTask;

/**
 * @author ZJL
 * @date 2025-03-10
 */
public class MainTest {
    public static void main(String[] args){

        long sum = 0;
        long threadSize = 3;
        for (int i = 1; i <= threadSize; i++) {
            SumThread sumThread = switch (i) {
                case 1 -> new SumThread(1, 100);
                case 2 -> new SumThread(101, 900);
                case 3 -> new SumThread(901, 1000);
                default -> null;
            };
            FutureTask<Long> futureTask = new FutureTask<>(sumThread);
            Thread thread = new Thread(futureTask);
            thread.start();
            try {
                sum += futureTask.get();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        System.out.println(sum);


//        SumThread sumThread1 = new SumThread(1, 100);
//        SumThread sumThread2 = new SumThread(101, 900);
//        SumThread sumThread3 = new SumThread(901, 1000);
//        FutureTask futureTask1 = new FutureTask(sumThread1);
//        FutureTask futureTask2 = new FutureTask(sumThread2);
//        FutureTask futureTask3 = new FutureTask(sumThread3);
//
//        Thread thread1 = new Thread(futureTask1);
//        Thread thread2 = new Thread(futureTask2);
//        Thread thread3 = new Thread(futureTask3);
//        thread1.start();
//        thread2.start();
//        thread3.start();
//
//        Long sum1 = (Long) futureTask1.get();
//        Long sum2 = (Long) futureTask2.get();
//        Long sum3 = (Long) futureTask3.get();
//
//        System.out.println(sum1+sum2+sum3);


    }
}
